package COMP;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class Importkinddata {
	
	private POIFSFileSystem fs;
	private HSSFWorkbook workbook;
	private HSSFSheet sheet;
	private String Inputfile;
	
	public Importkinddata(String filepath) {
		this.Inputfile = filepath;
	}
	
	public void start() throws FileNotFoundException, IOException{
		fs = new POIFSFileSystem(new FileInputStream(Inputfile));
		workbook = new HSSFWorkbook(fs);
		sheet = workbook.getSheetAt(0);
	}
	
	public String[][] getDataFromXLS(){
		HSSFRow hssfrow;
		HSSFCell hssfc;
		
		String[][] temp = new String[12][5];
		
		int[] index = {3,0,1,2,4};
		
		for(int i = 0; i < 12; i++){
			hssfrow = sheet.getRow(1+i);
			for(int j = 0; j < 5; j++){
				hssfc=hssfrow.getCell(1+j);
				
				String tempstr;
				
				if(hssfc==null){
					tempstr = "0";
				}else{
					tempstr = hssfc.getNumericCellValue()+"";
				}
				temp[i][index[j]] = tempstr;
			}
		}
		
		return temp;
	}
	
	public String getDataFromXLSCO2(){
		HSSFRow hssfrow;
		HSSFCell hssfc;
		
		hssfrow = sheet.getRow(1);
		hssfc=hssfrow.getCell(6);
		String tempstr;
		
		if(hssfc==null){
			tempstr = "0";
		}else{
			tempstr = hssfc.getNumericCellValue()+"";
		}
		
		return tempstr;
	}

}
